package cn.fu.common.convertion;


import java.beans.PropertyEditorSupport;

import cn.fu.core.bean.User2;
/**
 * 自定义属性编辑器类
 * 注：须在MVC中配制
 * 该类用于实现将String 类型转换成需要的数据类型
 * @author 15510
 *
 */
public class MyPropertyEditor extends PropertyEditorSupport {
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        User2 u = new User2();
        String[] textArray = text.split(",");
        u.setName(textArray[0]);
        u.setAge(Integer.parseInt(textArray[1]));
        this.setValue(u);
    }

    public static void main(String[] args) {
        MyPropertyEditor editor = new MyPropertyEditor();
        editor.setAsText("tom,22");
        System.out.println(editor.getValue());
    }
}
